package com.kdgz.kdgz.sevice.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kdgz.kdgz.beans.Salarys;
import com.kdgz.kdgz.mapper.SalaryMapper;
import com.kdgz.kdgz.sevice.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author Veneno
 * @Desc
 * @date 2021/4/6
 */
@Service
public class SalaryServiceImpl implements SalaryService {
    @Autowired
    SalaryMapper salaryMapper;

    @Override
    public Integer insertSalary(Salarys salarys) {
        return salaryMapper.insert(salarys);
    }

    @Override
    public List<Salarys> list(Integer sid) {
        QueryWrapper<Salarys> wrapper = new QueryWrapper<>();
        wrapper.eq("sid",sid);
        return salaryMapper.selectList(wrapper);
    }

    @Override
    public BigDecimal listByYear(Integer sid, Integer year) {
        QueryWrapper<Salarys> wrapper = new QueryWrapper<>();
        wrapper.eq("year(date)",year)
                .eq("sid",sid);
        List<Salarys> salarys = salaryMapper.selectList(wrapper);
        BigDecimal sum = new BigDecimal(0);
        for (Salarys salary : salarys) {
            sum = sum.add(salary.getSalary());
        }
        return sum;
    }

}
